package cn.csq.springcloudalibaba;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;

import javax.annotation.PostConstruct;

/**
 * @author csq
 * @date 2022/4/9 18:17:33
 */
@EnableDiscoveryClient
@SpringBootApplication
public class NacosConfigMainApplication {
    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(NacosConfigMainApplication.class, args);


        //String userName = applicationContext.getEnvironment().getProperty("user.name");
        //String userAge = applicationContext.getEnvironment().getProperty("user.age");
        //System.out.println("userName = "+userName+ " userAge = " + userAge);


        //support dynamic configuration updates
        //while (true) {
        //    String userName = applicationContext.getEnvironment().getProperty("user.name");
        //    String userAge = applicationContext.getEnvironment().getProperty("user.age");
        //    System.out.println("userName = "+userName+ " userAge = " + userAge);
        //    TimeUnit.SECONDS.sleep(1);
        //}
    }

    @Value("${user.name}")
    private String userName;

    @Value("${user.age}")
    private String userAge;

    @PostConstruct
    public void tests() {
        System.out.println("userName" + userName + " uerAge = " + userAge);
    }
}
